﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Castle.DynamicProxy;
using OOP.AOP.lib2.Attr;

namespace OOP.AOP.lib2.Aspect
{
    public class AuthorizationInterceptor : IInterceptor
    {

        public void Intercept(IInvocation invocation)
        {
            var attr = invocation.Method.GetCustomAttribute<AuthorizeAttribute>();
            if (attr != null && attr.Permission != "Admin")
            {
                throw new UnauthorizedAccessException($"Missing permission: {attr.Permission}");
            }

            invocation.Proceed();
        }
    }
}
